package head;

import java.util.Arrays;

public class a4_寻找两个正序数组的中位数 {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        int len = m + n;
        int[] nums = new int[m + n];
        for (int i = 0; i < m; i++) {
            nums[i] = nums1[i];
        }
        for (int j = m, i = 0; j < len; j++) {
            nums[j] = nums2[i++];
        }

        Arrays.sort(nums);
        if (len % 2 == 0) {
            return (nums[len / 2] + nums[(len / 2) - 1]) / 2.0;
        }
        if (len % 2 != 0) {
            return nums[len / 2];
        }
        return 0;

    }
}
